import client from "../db/index.ts";

export const getUser = async (ctx?: any) => {
  const user_id = ctx.state?.session.get("user_id")
  if (!user_id) return null;
  const result = await client.queryObject("SELECT * FROM sys_user WHERE id = $1", [user_id])
  return result.rows[0] as any
}

export const handleResult = (ctx: any, data: any) => {
  ctx.response.body = JSON.stringify({
    code: 0,
    resMsg: "操作成功",
    data
  })
}
export const handleError = (ctx: any, msg: string) => {
  ctx.response.body = JSON.stringify({
    code: 1,
    resMsg: msg,
    data: null
  })
}